//
//  Macros.h
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/9.
//  Copyright © 2017年 itboye. All rights reserved.
//

#ifndef Macros_h
#define Macros_h

// 系统相关宏 ————————————————————————————————————
// 打印
#ifdef DEBUG
#define DLog(fmt, ...)                              NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif

// 变量weak化和strong化
#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif

#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif

// 判断版本号
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([UIDevice currentDevice].systemVersion.doubleValue == v)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([UIDevice currentDevice].systemVersion.doubleValue > v)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([UIDevice currentDevice].systemVersion.doubleValue >= v)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([UIDevice currentDevice].systemVersion.doubleValue < v)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([UIDevice currentDevice].systemVersion.doubleValue <= v)

// 系统
#define APP_SCHEME                                  [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"]
#define APP_NAME                                    [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
#define APP_SHORT_VERSION                           [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define APP_BUNDLE_VERSION                          [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
#define APP_VERSION                                 [NSString stringWithFormat:@"%@.%@", APP_SHORT_VERSION,APP_BUNDLE_VERSION]

// 常用宏 ————————————————————————————
// 宽高
#define SCREEN_WIDTH                                ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT                               ([UIScreen mainScreen].bounds.size.height)
#define NAVIGATION_HEIGHT                           (isPhoneXAll?88.0:64.0)
#define BOTTOMPADDING_HEIGHT                        (isPhoneXAll?34.0:0)

#define isPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPhoneXsMax ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)
#define isPhoneXAll (isPhoneX || isPhoneXR || isPhoneXsMax)

#define iPhone4     ([UIScreen mainScreen].bounds.size.height==480.0f)
#define iPhone5S    ([UIScreen mainScreen].bounds.size.height==568.0f)
#define iPhone6     ([UIScreen mainScreen].bounds.size.height==667.0f)
#define iPhone6P    ([UIScreen mainScreen].bounds.size.height==736.0f)

#define H(h) round([UIScreen mainScreen].bounds.size.height / 667.0 * h)
#define W(w) round([UIScreen mainScreen].bounds.size.width / 375.0 * w)

// 颜色
#define rgba(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]

//弱引用化
#define WeakObj(o)  __weak typeof(o) o##Weak = o


#define kThemeColor rgba(34, 26, 11, 1)
#define kBgColor [UIColor colorWithWhite:0.95 alpha:1]
#define kLineColor [UIColor colorWithWhite:0.88 alpha:1]
#define kLineDarkColor [UIColor colorWithWhite:0.8 alpha:1]
#define kRedColor rgba(215, 90, 79, 1)
#define kGreenColor rgba(97, 192, 175, 1)
#define kBlueColor rgba(11, 175, 251, 1)
#define kBlueDarkColor rgba(71, 111, 128, 1)
#define kYellowColor rgba(247, 208, 95, 1)
#define kOrangeColor rgba(216, 154, 99, 1)
#define kPurpleColor rgba(240, 120, 185, 1)
#define kGrayColor rgba(54, 50, 48, 0.85)
#define kBlackColor [UIColor colorWithWhite:0.1 alpha:1]
#define kRouColor rgba(207, 165, 99, 0.9)
#define kBackgroundColor rgba(20, 21, 23, 0.9)




#define OR_FONT(size)   [UIFont fontWithName:@"Oswald-Regular-unhinted" size:size]
#define FONT(size)      [UIFont systemFontOfSize:size]
#define B_FONT(size)    [UIFont boldSystemFontOfSize:size]


#pragma mark - 用户相关
#define KZOnlineKey @"KZOnlineKey"
#define KZMacAddressKey @"KZMacAddressKey"
#define KZUserIDKey @"KZUserIDKey"


// 发送通知
#define KZPostNotification(name, obj) [[NSNotificationCenter defaultCenter] postNotificationName:name object:obj]

#define SystemIP @"SystemIP"

// 本地存储
#define KZSetUserDefaults(obj, key) [[NSUserDefaults standardUserDefaults] setObject:obj forKey:key]
#define KZGetUserDefaults(key)  [[NSUserDefaults standardUserDefaults] objectForKey:key]


#endif /* Macros_h */
